package cui.xin.studentcourse.controller;

import cui.xin.studentcourse.dto.MessageDto;
import cui.xin.studentcourse.dto.ResponseBean;
import cui.xin.studentcourse.service.MessageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *   公告和消息控制器
 * </p>
 *
 * @author palpitate_yzr
 * @since 2022年11月16日16:55:18
 */
@Slf4j
@RestController
@RequestMapping("/Message")
@Api(tags = "公告和消息")
public class MessageController {

    @Autowired
    private MessageService messageService;

    @RequestMapping("/getNotice")
    @ApiOperation(value = "公告",notes = "获取公告信息")
    public ResponseBean getNotice(){
       List<MessageDto> messageDto=messageService.getNotice();

        for (MessageDto dto : messageDto) {
            String da =dto.getNoticeTime();
            dto.setNoticeTime(da.substring(0, da.indexOf(" ")));
        }
       return new ResponseBean<>(messageDto);
    }


    @RequestMapping("/getMessage")
    @ApiOperation(value = "消息",notes = "获取消息信息")
    public ResponseBean getMessage(){
        List<MessageDto> messageDto=messageService.getMessage();
        for (MessageDto dto : messageDto) {
            String da =dto.getMessageTime();
            dto.setMessageTime(da.substring(da.indexOf(" ")));
        }
        return new ResponseBean<>(messageDto);
    }
}
